package test.edu.demo.Autowired;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author xiao.hu
 * @date 2021-08-28
 * @apiNote
 */
@Service
public class UserService {

    private IUser userAttribute;
    private String param;

    @Autowired
    private IUser user;


    @Autowired
    private List<IUser> userList;

    @Autowired
    private Set<IUser> userSet;

    @Autowired
    private Map<String, IUser> userMap;

    public void testCollection() {
        System.out.println("userList:" + userList);
        System.out.println("userSet:" + userSet);
        System.out.println("userMap:" + userMap);
    }


    @Autowired
    public UserService(IUser user) {
        this.userAttribute = user;
        System.out.println("Simple Construction user:" + userAttribute);
    }

    public UserService(@Autowired IUser user, String param) {
        this.param = param;
        this.user = user;
        System.out.println("Construction user:" + user);
    }

    /**
     * spring会在项目启动的过程中，自动调用一次加了@Autowired注解的方法，我们可以在该方法做一些初始化的工作。
     * @param user
     */
    @Autowired
    public void test(IUser user) {
        System.out.println("public void test(IUser user):" + user);
        user.say();
    }

    public void test2(@Autowired IUser user) {
        System.out.println("public void test(@Autowired IUser user, String param)");
        user.say();
        this.param = param;
    }

    /**
     * spring会在项目启动的过程中，自动调用一次加了@Autowired注解的方法，我们可以在该方法做一些初始化的工作。
     * @param user
     */
    @Autowired
    public void setUser(IUser user) {
        System.out.println("public void setUser(IUser user):" + user);
        this.user = user;
    }
}
